Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: moving cli config to --set for nodeport and storageclass #2083

Closed
wants to merge 41 commits into from

Conversation

bdw617
Copy link
Contributor

@bdw617 bdw617 commented Oct 18, 2023

Description

replace -nodeport and --storageclass: zarf init --nodeport <number> --storage-class <my-storage-class>
with: zarf init --set REGISTRY_NODEPORT=31998 --set REGISTRY_STORAGE_CLASS=my-storage-class

old variables still exist and work, but warnings are given to the user if they use them as deprecated.

NOTE: storageClass to be used for gitea and the registry will by default be the default storageClass of the cluster.

Related Issue

Fixes #1725

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • [x ] New feature (non-breaking change which adds functionality)
  • Other (security config, docs update, etc)

Checklist before merging

@netlify
Copy link

netlify bot commented Oct 18, 2023

Deploy Preview for zarf-docs canceled.

Name Link
🔨 Latest commit 5e7e182
🔍 Latest deploy log https://app.netlify.com/sites/zarf-docs/deploys/656534e212096f000893ec84

@bdw617 bdw617 marked this pull request as draft October 18, 2023 20:50
@bdw617 bdw617 added the needs-docs PR Label - Docs required to merge label Nov 15, 2023
@bdw617 bdw617 removed the needs-docs PR Label - Docs required to merge label Nov 17, 2023
@bdw617 bdw617 marked this pull request as ready for review November 27, 2023 14:55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more consistent with other deprecated fields/flags in the codebase, it would probably be good to rename the deprecated fields to DeprecatedStorageClass in the ZarfInitOptions struct, and DeprecatedNodePort in the RegistryInfo struct. This way we wouldn't need to add the nodePortArg and storageClassArg variables or remove any struct fields at this time.


if internalRegistry {
if configuredNodePort > 32767 || configuredNodePort < 30000 {
configuredNodePort = config.ZarfInClusterContainerRegistryNodePort
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably be good to notify the user that they provided an invalid nodeport number and that we're going to use the default Zarf nodeport of 31999 instead. Might save users some confusion on why their specified port number wasn't used by Zarf.

pkgConfig.InitOpts.RegistryInfo.NodePort = configuredNodePort
} else {
// do not set the nodeport if this is an external registry
pkgConfig.PkgOpts.SetVariables[configVar] = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to remove this else block. If the user specifies an external registry, we shouldn't have to set the REGISTRY_NODEPORT var to an empty string

storageClassArg = ""
setRegistryStorageClass()
if storageClassArg != "test-storage-class" {
t.Errorf("Expected storage class to be set to 'test-storage-class', but got '%s'", storageClassArg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use require.Equal() to be more consistent with the rest of our test suite assertions. When require.Equal() fails it prints an "expected but got" message by default for you.

storageClassArg = "old-storage-class"
setRegistryStorageClass()
if pkgConfig.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"] != "old-storage-class" {
t.Errorf("Expected storage class to be set to old way value, but got '%s'", pkgConfig.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use require.Equal() to be more consistent with the rest of our test suite assertions. When require.Equal() fails it prints an "expected but got" message by default for you.

storageClassArg = ""
setRegistryStorageClass()
if pkgConfig.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"] != "" {
t.Errorf("Expected storage class to be set to empty string, but got '%s'", pkgConfig.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use require.Equal() to be more consistent with the rest of our test suite assertions. When require.Equal() fails it prints an "expected but got" message by default for you.

}

if err != nil {
message.WarnErr(err, "Unable to get the default storage class from the cluster")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have an opportunity to fail fast here. If REGISTRY_PVC_ENABLED is true (this is the default), the user did not specify a storage class to use, and there was no default storage class found in the cluster, we should fail fast and notify the user that a storage class is needed for the registry to deploy successfully.

RKE2 clusters come to mind since they don't provide a default storage class

@@ -1,5 +1,5 @@
persistence:
storageClass: "###ZARF_STORAGE_CLASS###"
storageClass: "###ZARF_VAR_REGISTRY_STORAGE_CLASS###"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
storageClass: "###ZARF_VAR_REGISTRY_STORAGE_CLASS###"
storageClass: "###ZARF_VAR_GIT_SERVER_STORAGE_CLASS###"

default: "31999"
autoIndent: true

- name: REGISTRY_STORAGE_CLASS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a corresponding variable for the GIT_SERVER


// DEPRECATED_V1.0.0: --storage-class should be removed from the CLI in v1.0.0
func setRegistryStorageClass() {
configVar := "REGISTRY_STORAGE_CLASS"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would set both the registry and git server vars

// Zarf CLI deprecation warnings
const (
// remove deprecation in v1.0.0
WarnStorageClassDeprecated = "--storage-class <value> is deprecated, please use --set REGISTRY_STORAGE_CLASS=<value>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WarnStorageClassDeprecated = "--storage-class <value> is deprecated, please use --set REGISTRY_STORAGE_CLASS=<value>"
WarnStorageClassDeprecated = "--storage-class <value> is deprecated, please use --set REGISTRY_STORAGE_CLASS=<value> and --set GIT_SERVER_STORAGE_CLASS=<value>"


pkgConfig.InitOpts.RegistryInfo.InternalRegistry = internalRegistry

// TODO: test external registry and CLI.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo

@@ -167,7 +174,7 @@ $ zarf init --artifact-push-password={PASSWORD} --artifact-push-username={USERNA
CmdInitFlagGitPullPass = "Password for the pull-only user to access the git server"

CmdInitFlagRegURL = "External registry url address to use for this Zarf cluster"
CmdInitFlagRegNodePort = "Nodeport to access a registry internal to the k8s cluster. Between [30000-32767]"
CmdInitFlagRegNodePort = "[DEPRECATED] Nodeport to access a registry internal to the k8s cluster. Between [30000-32767]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CmdInitFlagRegNodePort = "[DEPRECATED] Nodeport to access a registry internal to the k8s cluster. Between [30000-32767]"
CmdInitFlagRegNodePort = "[Deprecated] Nodeport to access a registry internal to the k8s cluster. Between [30000-32767] (use --set REGISTRY_NODEPORT=<value> instead)"

p.cfg.PkgOpts.SetVariables = map[string]string{}
}
if c := p.cfg.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"]; c == "" {
p.cfg.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"], err = p.cluster.GetDefaultStorageClass()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be needed if the storage class is empty

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this with k3d, kind, k3s, and minikube locally across zarf v0.31.3 and this build, new inits and upgrades... do you have a test case where this was needed?

Comment on lines -253 to -257
if newState.RegistryInfo.Address == fmt.Sprintf("%s:%d", helpers.IPV4Localhost, newState.RegistryInfo.NodePort) {
newState.RegistryInfo.InternalRegistry = true
} else {
newState.RegistryInfo.InternalRegistry = false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this logic from here will break the library usages of zarf init - Nodeport should be pulled out of ZARF_VAR_REGISTRY_NODEPORT for now. (later this can be refactored to a more explicit mapping)

Comment on lines +88 to +95
if values.config.SetVariableMap != nil {
if regInfo.NodePort > 0 && values.config.SetVariableMap["REGISTRY_NODEPORT"] != nil {
values.config.SetVariableMap["REGISTRY_NODEPORT"].Value = fmt.Sprintf("%d", regInfo.NodePort)
}
if values.config.State.StorageClass != "" && values.config.SetVariableMap["REGISTRY_STORAGE_CLASS"] != nil {
values.config.SetVariableMap["REGISTRY_STORAGE_CLASS"].Value = values.config.State.StorageClass
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be here - variables in a zarf.yaml will just pass through

Comment on lines +84 to +85
// removed
//StorageClass string `json:"storageClass" jsonschema:"description=StorageClass of the k8s cluster Zarf is initializing"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code should be deleted - it will still be in git if we ever need it

@lucasrod16
Copy link
Contributor

Closing this PR because we will likely rethink the implementation

@lucasrod16 lucasrod16 closed this May 8, 2024
@lucasrod16 lucasrod16 deleted the issue-1725 branch May 8, 2024 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make non-credential init values Zarf variables instead
3 participants